﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Web;

namespace Idte.Application.PDN.Models
{
    public class PDNDatabaseInitializer : DropCreateDatabaseIfModelChanges<PDNContext>
    {
        protected override void Seed(PDNContext context)
        {
            CompetencyAnswer a1 = new CompetencyAnswer() {Title = "Answer 1", Text = "This is answer A1" };
            CompetencyAnswer a2 = new CompetencyAnswer() {Title = "Answer 2", Text = "This is answer A2" };
            CompetencyAnswer a3 = new CompetencyAnswer() {Title = "Answer 3", Text = "This is answer A3" };
            CompetencyAnswer a4 = new CompetencyAnswer() {Title = "Answer 4", Text = "This is answer A4" };
            CompetencyAnswer a5 = new CompetencyAnswer() {Title = "Answer 5", Text = "This is answer A5" };

            CompetencyQuestion lq1 = new CompetencyQuestion() { Title = "Question 1", Text = "This is question 1" };
            CompetencyQuestion lq2 = new CompetencyQuestion() { Title = "Question 2", Text = "This is question 2" };
            CompetencyQuestion lq3 = new CompetencyQuestion() { Title = "Question 3", Text = "This is question 3" };

            Category c1 = new Category() { Id = 1, Name = "Uncategorized" };
            Category c2 = new Category() { Id = 2, Name = "Cat1" };
            Category c3 = new Category() { Id = 3, Name = "Cat2" };
            Category c4 = new Category() { Id = 4, Name = "Cat3" };
            Category c5 = new Category() { Id = 5, Name = "Cat5" };
            Category c6 = new Category() { Id = 6, Name = "Cat6" };
           
            List<Category> cl = new List<Category>();
            cl.Add(c5); cl.Add(c6);
            Category c7 = new Category() { Id = 7, Name = "Cat7", SubCategories = cl};
            Category c8 = new Category() { Id = 8, Name = "Cat8" };
            List<Category> cl2 = new List<Category>();
            cl2.Add(c8);
            Category c9 = new Category() { Id = 9, Name = "Cat9", SubCategories = cl2 };
            List<Category> cl3 = new List<Category>();
            cl3.Add(c9);
            Category c10 = new Category() { Id = 10, Name = "Cat10", SubCategories = cl3 };
            List<Category> cl4 = new List<Category>();
            cl4.Add(c10);
            Category c11 = new Category() { Id = 11, Name = "Cat11", SubCategories = cl4 };

            CategoryAnswer ca1 = new CategoryAnswer() {Answer = a1, Category = c1 };
            CategoryAnswer ca2 = new CategoryAnswer() { Answer = a1, Category = c2 };
            CategoryAnswer ca3 = new CategoryAnswer() { Answer = a4, Category = c3 };
            CategoryAnswer ca4 = new CategoryAnswer() { Answer = a2, Category = c4 };
            CategoryAnswer ca5 = new CategoryAnswer() { Answer = a3, Category = c1 };
            CategoryAnswer ca6 = new CategoryAnswer() {Answer = a5, Category = c3 };

            context.Set<Category>().Add(c11);
            context.Set<Category>().Add(c7);

            context.Set<CategoryAnswer>().Add(ca1);
            context.Set<CategoryAnswer>().Add(ca2);
            context.Set<CategoryAnswer>().Add(ca3);
            context.Set<CategoryAnswer>().Add(ca4);
            context.Set<CategoryAnswer>().Add(ca5);
            context.Set<CategoryAnswer>().Add(ca6);

            CategoryQuestion ct1 = new CategoryQuestion() { Category = c2, Question = lq1 };
            CategoryQuestion ct2 = new CategoryQuestion() { Category = c2, Question = lq2 };
            CategoryQuestion ct3 = new CategoryQuestion() { Category = c3, Question = lq2 };
            CategoryQuestion ct4 = new CategoryQuestion() { Category = c3, Question = lq3 };
            CategoryQuestion ct5 = new CategoryQuestion() { Category = c4, Question = lq1 };
            CategoryQuestion ct6 = new CategoryQuestion() { Category = c4, Question = lq3 };

            List<CategoryQuestion> lcq = new List<CategoryQuestion>();
            CategoryQuestion test = new CategoryQuestion() {CategoryId = 1 };
            lcq.Add(test);
            CompetencyQuestion lq4 = new CompetencyQuestion() { Title = "Question Test", Text = "This is question test", CategoryQuestions = lcq };


            context.Set<CompetencyQuestion>().Add(lq4);
            context.Set<CategoryQuestion>().Add(ct1);
            context.Set<CategoryQuestion>().Add(ct2);
            context.Set<CategoryQuestion>().Add(ct3);
            context.Set<CategoryQuestion>().Add(ct4);
            context.Set<CategoryQuestion>().Add(ct5);
            context.Set<CategoryQuestion>().Add(ct6);
            context.Set<Category>().Add(c1);

            

            QuestionAnswer qa1 = new QuestionAnswer() { Question = lq1, Answer = a1, Correct = false };

            QuestionAnswer qa2 = new QuestionAnswer() { Question = lq2, Answer = a2, Correct = true };
            QuestionAnswer qa3 = new QuestionAnswer() { Question = lq2, Answer = a3, Correct = false };

            QuestionAnswer qa4 = new QuestionAnswer() { Question = lq3, Answer = a5, Correct = true };
            QuestionAnswer qa5 = new QuestionAnswer() { Question = lq3, Answer = a4, Correct = false };
            QuestionAnswer qa6 = new QuestionAnswer() { Question = lq3, Answer = a3, Correct = false };

            context.Set<QuestionAnswer>().Add(qa1);
            context.Set<QuestionAnswer>().Add(qa2);
            context.Set<QuestionAnswer>().Add(qa3);
            context.Set<QuestionAnswer>().Add(qa4);
            context.Set<QuestionAnswer>().Add(qa5);
            context.Set<QuestionAnswer>().Add(qa6);

            AnswerLinkQuestion alq1 = new AnswerLinkQuestion() { Answer = a2, AQuestion = lq1 };
            AnswerLinkQuestion alq2 = new AnswerLinkQuestion() { Answer = a2, AQuestion = lq2 };
            AnswerLinkQuestion alq3 = new AnswerLinkQuestion() { Answer = a1, AQuestion = lq1 };
            AnswerLinkQuestion alq4 = new AnswerLinkQuestion() { Answer = a1, AQuestion = lq3 };
            AnswerLinkQuestion alq5 = new AnswerLinkQuestion() { Answer = a3, AQuestion = lq2 };
            AnswerLinkQuestion alq6 = new AnswerLinkQuestion() { Answer = a3, AQuestion = lq3 };

            context.Set<AnswerLinkQuestion>().Add(alq1);
            context.Set<AnswerLinkQuestion>().Add(alq2);
            context.Set<AnswerLinkQuestion>().Add(alq3);
            context.Set<AnswerLinkQuestion>().Add(alq4);
            context.Set<AnswerLinkQuestion>().Add(alq5);
            context.Set<AnswerLinkQuestion>().Add(alq6);

            AnswerLinkCategory alc1 = new AnswerLinkCategory() {Answer = a1, Category = c1 };
            AnswerLinkCategory alc2 = new AnswerLinkCategory() { Answer = a1, Category = c2 };
            AnswerLinkCategory alc3 = new AnswerLinkCategory() { Answer = a2, Category = c1 };
            AnswerLinkCategory alc4 = new AnswerLinkCategory() { Answer = a2, Category = c3 };
            AnswerLinkCategory alc5 = new AnswerLinkCategory() { Answer = a3, Category = c3 };
            AnswerLinkCategory alc6 = new AnswerLinkCategory() { Answer = a3, Category = c2 };

            context.Set<AnswerLinkCategory>().Add(alc1);
            context.Set<AnswerLinkCategory>().Add(alc2);
            context.Set<AnswerLinkCategory>().Add(alc3);
            context.Set<AnswerLinkCategory>().Add(alc4);
            context.Set<AnswerLinkCategory>().Add(alc5);
            context.Set<AnswerLinkCategory>().Add(alc6);

            context.SaveChanges(); // Save 'em
        }
        


    }
}